using HCore.IOC.Beans.Factory.Attribute.Attr;
using HCore.IOC.Context.Event.Attr;
using HCore.IOC.Context.Stereotype;
using HCore.Tests.Runtime.ShootingEditor2D.Scripts.Support.CommandQuery;
using HCore.Tests.Runtime.ShootingEditor2D.Scripts.System.GunSystem;

namespace HCore.Tests.Runtime.ShootingEditor2D.Scripts.Command
{
    /// <summary>
    ///     捡枪
    /// </summary>
    public class PickGunCommand : ICommand
    {
        /// <summary>
        ///     初始化捡枪命令实例
        /// </summary>
        /// <param name="gunName">枪支名称</param>
        /// <param name="bulletCountInGun">枪内子弹数量</param>
        /// <param name="bulletCountOutGun">枪外子弹数量</param>
        public PickGunCommand(string gunName, int bulletCountInGun, int bulletCountOutGun)
        {
            Name = gunName;
            BulletCountOutGun = bulletCountOutGun;
            BulletCountInGun = bulletCountInGun;
        }

        /// <summary>
        ///     获取枪支名称
        /// </summary>
        public string Name { get; }

        /// <summary>
        ///     获取枪内子弹数量
        /// </summary>
        public int BulletCountInGun { get; }

        /// <summary>
        ///     获取枪外子弹数量
        /// </summary>
        public int BulletCountOutGun { get; }
    }

    /// <summary>
    ///     捡枪命令处理器
    ///     负责处理捡枪命令，调用枪支系统执行捡枪操作
    /// </summary>
    [Component]
    public class PickGunCommandHandler
    {
        [Autowired] private IGunSystem mGunSystem;

        /// <summary>
        ///     执行捡枪命令
        ///     调用枪支系统完成捡枪操作
        /// </summary>
        /// <param name="command">捡枪命令对象，包含枪支名称和子弹数量信息</param>
        [EventListener]
        public void ExecuteCommand(PickGunCommand command)
        {
            mGunSystem.PickGun(command.Name, command.BulletCountInGun, command.BulletCountOutGun);
        }
    }
}